<?php

namespace Admin\Controller;

use Think\Controller;
use Think\Verify;

class LoginController extends Controller {
    //输出验证码
    public function verify(){
        $Verify = new Verify();   //实例化verify类 2.完全限定名称 方式
        $Verify->fontSize = 18;
        $Verify->length   = 4;
        $Verify->useNoise = false;
        $Verify->codeSet = '0123456789';
        $Verify->imageW = 130;
        $Verify->imageH = 50;
        $Verify->entry();        //输出验证码
    }

    //后台登录
    public function index(){
        if(IS_POST){
            $list = I('post.');
            $vry = new Verify;
            if(!$vry -> check($list['verify'])){
                $this->error('验证码错误!');
            }
            if(empty($list['user']) && empty($list['password'])){
                $this->error('用户或密码不正确!');
            }
            $admin = M('blog_admin')->where(array('user' => $list['user'], 'password' => md5(md5($list['password'])),'status' => 1))->find();
            if(!$admin){
                $this->error('用户或密码不正确!');
            }else{
                $this->success('登录成功',U('admin/index/index'));
            }
        }
        $this->display();

    }
}



